﻿using Abp.Domain.Repositories;
using Abp.Runtime.Caching;
using AVIS.OutBound.AWD;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AVIS.OutBound.AWD.Cache;
using AVIS.OutBound.AWD.Dto;
using Abp.AutoMapper;
using Abp.ObjectMapping;

namespace AVIS.OutBound.AWD
{
    /// <summary>
    /// Avis全球折扣号，全称为：Avis Worldwide Discount
    /// </summary>
    public class AWDAppService : OutBoundAppServiceBase, IAWDAppService
    {
        #region
        private readonly IAWDManager _AWDManager;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="awdManager"></param>
        public AWDAppService(IAWDManager awdManager)
        {
            _AWDManager = awdManager;
        }
        #endregion

        /// <summary>
        /// 校验AWD验证码
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public bool CheckAWD(CheckAWDInput input)
        {
            var awdNumber = _AWDManager.GetAWDNumberCache(input.AWDCode);
            if (awdNumber == null)
            {
                return false;
            }

            return awdNumber.CheckAWDPassword(input.Password);
        }

        /// <summary>
        /// 是否需要验证密码
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public NeedCheckAWDOutput NeedCheckAWD(NeedCheckAWDInput input)
        {
            var awdNumber = _AWDManager.GetAWDNumberCache(input.AWDCode);
            if (awdNumber != null && awdNumber.NeedCheckAWD() == true)
            {
                return new NeedCheckAWDOutput { NeedCheckPWD = true, Prompt = awdNumber.Remark };
            }
            else
            {
                return new NeedCheckAWDOutput { NeedCheckPWD = false };
            }
        }
    }
}
